package bb.lanxing.lib.kt.model.geo;

import android.os.Parcel;
import android.os.Parcelable;

public class GeoBounds implements Parcelable {
    public static final Parcelable.Creator<GeoBounds> CREATOR = new Parcelable.Creator<GeoBounds>() {
        @Override
        public GeoBounds createFromParcel(Parcel parcel) {
            return new GeoBounds(parcel);
        }

        @Override
        public GeoBounds[] newArray(int i) {
            return new GeoBounds[i];
        }
    };
    public final double east;
    public final double north;
    public final double south;
    private int type;
    public final double west;

    @Override
    public int describeContents() {
        return 0;
    }

    public GeoBounds(int i, double d, double d2, double d3, double d4) {
        this.type = i;
        this.north = d;
        this.east = d2;
        this.south = d3;
        this.west = d4;
    }

    public boolean contain(IGeoPoint iGeoPoint) {
        if (iGeoPoint == null) {
            return false;
        }
        double latitude = iGeoPoint.getLatitude();
        double longitude = iGeoPoint.getLongitude();
        return latitude >= this.south && latitude <= this.north && longitude >= this.west && longitude <= this.east;
    }

    public IGeoPoint getCenter() {
        return new SimpleGeoPoint(IGeoPoint.TYPE_EARTH, (this.north + this.south) / 2.0d, (this.east + this.west) / 2.0d);
    }

    public int getType() {
        return this.type;
    }

    public GeoBounds toType(int i) {
        if (i == this.type) {
            return this;
        }
        IGeoPoint type = new SimpleGeoPoint(this.type, this.north, this.east).toType(i);
        IGeoPoint type2 = new SimpleGeoPoint(this.type, this.south, this.west).toType(i);
        return new GeoBounds(i, type.getLatitude(), type.getLongitude(), type2.getLatitude(), type2.getLongitude());
    }

    public static class Builder {
        private double east;
        private boolean first = true;
        private double north;
        private double south;
        private double west;

        public void include(double d, double d2) {
            if (this.first) {
                this.south = d;
                this.north = d;
                this.west = d2;
                this.east = d2;
                this.first = false;
            }
            if (d > this.north) {
                this.north = d;
            }
            if (d < this.south) {
                this.south = d;
            }
            if (d2 < this.west) {
                this.west = d2;
            }
            if (d2 > this.east) {
                this.east = d2;
            }
        }

        public GeoBounds build(int i) {
            return new GeoBounds(i, this.north, this.east, this.south, this.west);
        }
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeDouble(this.north);
        parcel.writeDouble(this.east);
        parcel.writeDouble(this.south);
        parcel.writeDouble(this.west);
    }

    protected GeoBounds(Parcel parcel) {
        this.north = parcel.readDouble();
        this.east = parcel.readDouble();
        this.south = parcel.readDouble();
        this.west = parcel.readDouble();
    }
}
